package com.caregiver.watch.business.care.model.dto;

import com.alibaba.fastjson2.JSON;
import com.caregiver.watch.business.care.enums.FenceRemindTypeEnum;
import com.caregiver.watch.business.care.model.po.FenceSetting;
import com.caregiver.watch.common.utils.time.DateUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.List;

import static com.caregiver.watch.common.constant.NumberConstants.ONE;
import static com.caregiver.watch.common.utils.time.DateUtils.HH_MM;

/**
 * 新增围栏设置参数
 * @program: caregiver-watch
 * @author: 疆戟
 * @create: 2025-10-06 09:10
 */
@Data
@Schema(description = "新增围栏设置参数")
public class AddFenceSettingParam {

    @Schema(description = "围栏名称")
    @NotBlank(message = "围栏名称不能为空")
    private String fenceName;

    @Schema(description = "开始时间(HH:mm)")
    private String startTime;

    @Schema(description = "结束时间(HH:mm)")
    private String endTime;

    @Schema(description = "提醒方式")
    @NotBlank(message = "提醒方式不能为空")
    private FenceRemindTypeEnum fenceRemindType;

    @Schema(description = "围栏经纬度数据")
    private List<FenceLocation> fenceLocations;

    @Schema(description = "围栏生效的照护人ID列表")
    private List<FenceRecipientInfo> fenceRecipientInfos;

    public FenceSetting toPo(Long userId) {
        FenceSetting po = new FenceSetting();
        po.setUserId(userId);
        po.setFenceName(fenceName);
        po.setStartTime(DateUtils.parseTime(startTime, HH_MM));
        po.setEndTime(DateUtils.parseTime(endTime, HH_MM));
        po.setFenceRemindType(fenceRemindType);
        po.setFenceData(JSON.toJSONString(fenceLocations));
        po.setEnable(ONE);
        return po;
    }
}
